package cn.dubito.miaosha.utils;


import org.springframework.util.DigestUtils;

/**
 * @author liliang
 * @description:
 * @date 2018/3/29.
 */
public class MD5Util {

    private static final String SALT = "123asd4";

    public static String md5(String src) {
        return DigestUtils.md5DigestAsHex(src.getBytes());
    }

    private static String inputPassToFormPass(String inputPass) {
        String str = "" + SALT.charAt(0) + SALT.charAt(3) + SALT.charAt(4) + inputPass + SALT.charAt(5) + SALT.charAt(2);
        return md5(str);
    }

    private static String formPassToDbPass(String formPass, String salt) {
        String str = "" + salt.charAt(0) + salt.charAt(3) + salt.charAt(4) + formPass + salt.charAt(5) + salt.charAt(2);
        return md5(str);
    }

    public static String passToDb(String input,String salt) {
        return formPassToDbPass(inputPassToFormPass(input),salt);
    }



    public static void main(String[] args) {

        System.out.println(passToDb("123456","1234asdf"));
    }
}
